// @algorithm @lc id=100304 lang=cpp
// @title lian-xu-zi-shu-zu-de-zui-da-he-lcof

#include "algm/algm.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
    // @test([1])=1
public:
    int maxSubArray(vector<int> &nums) {
        int n = nums.size();
        int ans = INT_MIN;
        if (n == 0) {
            return 0;
        }
        vector<int> dp(n, INT_MIN);
        dp[0] = nums[0];
        ans = dp[0];
        for (int i = 1; i < n; ++i) {
            dp[i] = max(dp[i - 1] + nums[i], nums[i]);
            ans = max(ans, dp[i]);
        }
        return ans;
    }
};